<template>
	<view class="pageBox">
		<view class="main">
			<!-- <view class="main_top">
				<view class="left">
					<view class="name">
						新人专享
					</view>
					<view class="desc">
						限时兑换
					</view>
				</view>
				<view class="right">
					<uni-countdown :show-day="false" :second="86400" @timeup="timeOut()" />
				</view>
			</view> -->
			<view class="main_bot">
				<view class="item" v-for="(item,index) in productList" :key="index" @click="jumpDetil(item.id)">
					<view class="item_box">
						<view class="left">
							<image :src="item.mainImage[0]" mode="aspectFill" class="img"></image>
						</view>
						<view class="right">
							<view class="name">
								{{item.name}}
							</view>
							<view class="desc">
								<text v-for="(itemA,indexA) in item.benefitPoints" :key="indexA">
								 <text class="text_right">{{itemA}}</text>
								 <text class="text_xhx" v-if="indexA!==item.benefitPoints.length-1">|</text>
								</text>
							</view>
							<view class="con">
								<view class="con_poiAll">
									<view class="con_points">
										{{item.integral}}积分
									</view>
									<!-- <view class="con_price">
										市场价¥{{item.marketPrice}}元
									</view> -->
								</view>
								<view class="con_btn" @click.stop="jumpDetilBuy(item)">
									{{item.canBuy?'免费使用':'积分兑换'}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="item_kong" v-if="isLastPage">
					没有更多了
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	import {
		apiOperationProductNewList,apiPointSeuityList
	} from '../../apis/my.js';
	export default {
		data() {
			return {
				location: "",
				productList:[],
				currentPage:1,
				isLastPage: false,
			}
		},
		onLoad(option){
			let that = this;
			that.location = app.globalData.latitude + "," + app.globalData.longitude;
			
			
		},
		onShow(){
			this.currentPage=1
			this.getList();
		},
		methods: {
			getList() {
				var that = this;
				uni.hideLoading();
				const params = {
					page: that.currentPage,
					pageSize: 10,
					pagination:true,
					lat: that.location.split(',')[0],
					lng: that.location.split(',')[1],
				}
				apiPointSeuityList(params).then(res => {
					switch (res.code) {
						case 0:
							that.total_page = res.data.totalCount;
							that.loading = false;
							that.isLastPage = res.data.lastPage;
							if (res.data.list.length > 0) {
								that.productList = that.currentPage == 1 ? res.data.list : that.productList
									.concat(res.data.list);
								console.log(that.productList, "商品列表")
							}
							break;
						default:
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							break;
					}
				})
			
			},
			jumpDetil(id){
				uni.navigateTo({
					url: `/pageC/pointEquity/pointEquity?store_id=${id}`
				})
			},
			jumpDetilBuy(item){
				console.log("立即兑换")
				uni.navigateTo({
					url: `/pageC/pointEquity/pointEquity?store_id=${item.id}&isbuy=${item.canBuy?'':2}`
				})
			},
			
		},
		onReachBottom() {
			
			if (!this.isLastPage) {
				this.currentPage++;
				this.getList();
			
			} else {
				return
			}
		},
	}
</script>

<style lang="scss">
page {
	background: #f9f9f9;
}
.pageBox{
	width: 100%;
	.main{
		margin: 22rpx 28rpx 0;
		.main_top{
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left{
				display: flex;
				align-items: center;
				.name{
					font-family: PingFangSC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
				}
				.desc{
					width: 80rpx;
					height: 26rpx;
					background: #FF5608;
					border-radius: 4rpx;
					margin-left: 14rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 18rpx;
					color: #FFFFFF;
					display: flex;
					align-items: center;
					justify-content: center;
					.text_xhx{
						margin: 0 10rpx;
					}
				}
			}
			.right{
				font-family: PingFangSC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}
		.main_bot{
			width: 100%;
			margin-top: 20rpx;
			.item{
				width: 100%;
				height: 160rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				margin-bottom: 24rpx;
				padding: 24rpx 0;
				.item_box{
					padding: 0 24rpx;
					display: flex;
					.left{
						width: 160rpx;
						height: 160rpx;
						.img{
							width: 160rpx;
							height: 160rpx;
							border-radius: 12rpx;
						}
					}
					.right{
						padding-left: 24rpx;
						flex: 1;
						.name{
							font-family: PingFangSC, PingFang SC;
							font-weight: bold;
							font-size: 28rpx;
							color: #333333;
							word-break: break-all;
							white-space: pre-wrap;
							word-wrap: break-word;
							overflow: hidden;
							display: -webkit-box;
							text-overflow: ellipsis;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 1;
						}
						.desc{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #B1B1B1;
							padding: 12rpx 0 6rpx;
							word-break: break-all;
							white-space: pre-wrap;
							word-wrap: break-word;
							overflow: hidden;
							display: -webkit-box;
							text-overflow: ellipsis;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 1;
							.text_xhx{
								margin: 0 10rpx;
							}
						}
						.con{
							display: flex;
							align-items: center;
							justify-content: space-between;
							padding-top: 10rpx;
							.con_poiAll{
								display: flex;
								flex-direction: column;
								.con_points{
									font-family: PingFangSC, PingFang SC;
									font-weight: 500;
									font-size: 28rpx;
									color: #F15A3C;
								}
								.con_price{
									font-family: PingFangSC, PingFang SC;
									font-weight: 400;
									font-size: 20rpx;
									color: #999999;
								}
							}
							.con_btn{
								width: 160rpx;
								height: 52rpx;
								background: linear-gradient( 143deg, #FB8E2D 0%, #FC5A28 100%);
								box-shadow: 0rpx 4rpx 8rpx 0rpx #FFD7D7;
								border-radius: 26rpx;
								font-family: PingFangSC, PingFang SC;
								font-weight: 500;
								font-size: 24rpx;
								color: #FFFFFF;
								display: flex;
								align-items: center;
								justify-content: center;
							}
						}
					}
				}
			}
			.item_kong{
				width: 100%;
				padding: 30rpx 0;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 24rpx;
				color: #999;
			}
		}
	}
}
</style>
